/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sgsmcan.Dao;

import com.sgsmcan.Entidad.Permiso;
import com.sgsmcan.Hibernate.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author user
 */
public class PermisoDaoImpl extends HibernateDao<Permiso> implements PermisoDao{

    @Override
    public List<Permiso> getPermisosPorPerfil(int id) {
        Session session = null;
        List<Permiso> aux = null;
        try{
            session = HibernateUtil.getSessionFactory().openSession();
            Criteria criteria = session.createCriteria(Permiso.class,"permi").add(Restrictions.eq("permi.perfil.id",id)).addOrder(Order.asc("permi.modulo.id"));
            aux = criteria.list();
            return aux;
        }catch(HibernateException e){
           
            throw new HibernateException(e);
        }finally{
            if(session != null){
                session.close();
            }
        }
    }
    
}
